{extend name="adminblue/base" /}
{block name="resources"/}
<style>
.is-enabled{display: block;width:15px;cursor: pointer;}
</style>
{/block}
{block name="main"}
	<table class="mytable">
		<tr>
			<th>
			虚拟商品名称：
				<input type="text" id='search_name' placeholder="输入虚拟商品名称" class="input-common middle"/>
			虚拟商品编号：
				<input type="text" id='virtual_code' placeholder="输入虚拟商品编号" class="input-common middle"/>
			状态：
			<select id="use_status" class="select-common middle" >
				<option value="" >全部</option>
				<option value="1">已使用</option>
				<option value="-1">已过期</option>
				<option value="0" >未使用</option>
			</select>
			<button onclick="LoadingInfo(1)" class="btn-common">搜索</button>
			</th>
		</tr>
	</table>

	<table class="table-class">
		<colgroup>
		<col style="width: 3%;">
		<col style="width: 10%;">
		<col style="width: 12%;">
		<col style="width: 15%;">
		<col style="width: 10%;">
		<col style="width: 15%;">
		<col style="width: 15%;">
		<col style="width: 10%;">
		<col style="width: 15%;">
		</colgroup>
		<thead>
			<tr>
				<th><i class="checkbox-common"><input type="checkbox" onclick="CheckAll(this)" /></i></th>
				<th align="left">商品名称</th>
				<th align="left">虚拟码</th>
				<th>已使用次数/总次数</th>
				<th>买家</th>
				<th>开始时间</th>
				<th>结束时间</th>
				<th>状态</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody></tbody>
	</table>
{/block}
{block name="script"}
<script type="text/javascript">

//加载数据
function LoadingInfo(page_index) {
	var search_name = $("#search_name").val();
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/VirtualGoods/virtualGoodsList')}",
		data : {
			"page_index" : page_index,
			"page_size" : $("#showNumber").val(),
			"search_name" : search_name,
			"use_status" : $("#use_status").val(),
			"virtual_code" : $("#virtual_code").val()
		},
		success : function(data) {
			
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {	
					var html = '';
					if( data["data"][i]["confine_use_number"] == 0){
						var number_info = "不限次数";
					}else{
						var number_info = data["data"][i]["confine_use_number"];
					}
					html += '<tr align="center">';
					html += '<td><i class="checkbox-common"><input name="sub" type="checkbox" value="'+ data["data"][i]["virtual_goods_id"] +'" ></i></td>';
					if(data["data"][i]["goods_name"] != null){
						html += '<td align="left">' + data["data"][i]["goods_name"] + '</td>';
					}else{
						html += '<td align="left"></td>';
					}
					html += '<td align="left">'+data["data"][i]["virtual_code"]+'</td>';
					html += '<td>'+data["data"][i]["use_number"]+'/'+ number_info +'</td>';
					
 					var row=1;//订单数量，用于设置跨行
					html += '<td>'+data["data"][i]["nick_name"]+'</td>';
					html += '<td>'+timeStampTurnTime(data["data"][i]["start_time"])+'</td>';
					if(data["data"][i]["end_time"] != 0){
						html += '<td>'+timeStampTurnTime(data["data"][i]["end_time"])+'</td>';
					}else{
						html += '<td>不限制</td>';
					}
					
	                if (data["data"][i]["use_status"] == - 1) {
	                	var use_status = '已过期';
	                } else if (data["data"][i]["use_status"] == 0) {
	                	var use_status = '未使用';
	                } else if (data["data"][i]["use_status"] == 1) {
	                	var use_status = '已使用';
	                }
					html += '<td>'+use_status+'</td>';
					html += '<td>';
					if(data["data"][i]["use_status"] == 0){
						html += '<a href="javascript:verificationVirtualGoods(' + data["data"][i]["virtual_goods_id"] + ', ' + data["data"][i]["buyer_id"] + ')">核销</a>';
					}
					html +='</td></tr>';

					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}
//全选
function CheckAll(event){
	var checked = event.checked;
	if(checked) $(".table-class tbody input[type = 'checkbox']").prop("checked",checked).parent().addClass("selected");
	else $(".table-class tbody input[type = 'checkbox']").prop("checked",checked).parent().removeClass("selected");

}
//核销
function verificationVirtualGoods(virtual_goods_id,buyer_id){
	$( "#dialog" ).dialog({
		buttons: {
			"确定": function() {
				$.ajax({
					type : "post",
					url : "{:__URL('ADMIN_MAIN/verification/verificationVirtualGoods')}",
					data : { "virtual_goods_id" : virtual_goods_id.toString(),"buyer_id" : buyer_id },
					dataType : "json",
					success : function(data) {
						if(data["code"] > 0 ){
							$("#dialog").dialog({
								buttons: {
									"确定": function() {
										$(this).dialog('close');
									}
								},
								modal: true,
								contentText:data["message"],
								title:"消息提醒",
								time:1
							});
							LoadingInfo($(".currentPage").text());
							$("#chek_all").prop("checked", false);
						}else{
							$("#dialog").dialog({
								buttons: {
									"确定,#0059d6,#fff": function() {
										$(this).dialog('close');
									}
								},
								modal: true,
								contentText:data["message"],
								title:"消息提醒",
								time:1
							});
						}
					}
				});
				$(this).dialog('close');
			},
			"取消,#f5f5f5,#666": function() {
				$(this).dialog('close');
			},
		},
		contentText:"确定要此操作吗？",
	});
}



</script>
{/block}